package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//删除一条记录id为1
public class Demo04 {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement pps = null;

        //注册驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");

            con = DriverManager.getConnection("jdbc:mysql:///db2", "root", "myroot");

            String sql = "delete from account where id = ?";

            pps = con.prepareStatement(sql);
            pps.setInt(1, 1);

            int i = pps.executeUpdate();


            System.out.println(i);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                if (pps != null) {
                    try {
                        pps.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
